package com.example.gulimall.product.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * mybatisPlus 自动分页插件
 */
@Configuration
@EnableTransactionManagement
@MapperScan("com.example.guliamll.product.dao")
public class MybatisPlusConfig {

    // 最新版 分页拆件
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
//        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
//        //设置请求页面大于最大页后。true回到首页，false继续请求 默认false
//        paginationInnerInterceptor.setOverflow(true);
//        //设置最大当条限制，默认500，-1不受限制
//        paginationInnerInterceptor.setMaxLimit(1000L);
////        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
////        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
//        return paginationInnerInterceptor;
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));//如果配置多个插件,切记分页最后添加
        //interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); 如果有多数据源可以不配具体类型 否则都建议配上具体的DbType
        return interceptor;
    }

}

